
/*
 *************************************************************************
 *西瑞克斯研发管理系统
 *版 本: 1.0   
 *日 期：02/11/2012    
 *作 者： 王浩 QQ：873987060   
 *************************************************************************   
 */
package com.application.yfexamine.dao;

import java.util.List;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import com.manager.commons.page.PageBean;
import org.apache.log4j.Logger;
import com.manager.commons.dao.HibernateGenericDao;
import com.manager.commons.page.PageBean;
import com.application.yfexamine.entity.YfExmaine;
import com.application.yfexamine.struts.form.YfExmaineForm;

/**
 * 
 * Description:YfExmaineDAO<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/11/2012
 * 
 */
public class YfExmaineDAO extends HibernateGenericDao<YfExmaine> {
	private static final Logger logger = Logger.getLogger(YfExmaineDAO.class);

	private YfExmaine yfExmaine;

	public YfExmaine getYfExmaine() {
		return this.yfExmaine;
	}

	public void setYfExmaine(YfExmaine yfExmaine) {
		this.yfExmaine = yfExmaine;
	}

	public Integer getAllCountYfExmaine(YfExmaineForm yfExmaineForm) {
		List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(0) FROM yf_exmaine WHERE 1=1 ");
		sql = getStringBuffer(yfExmaineForm, sql, args);
		return super.getCount(sql.toString(), args.toArray());
	}

	public void deleteYfExmaines(YfExmaineForm yfExmaineForm) {
		String hql = " delete from YfExmaine where id in  ( '" + yfExmaineForm.getIds() + "')";
		Session session = this.getSession();
		try {
			session.createQuery(hql).executeUpdate();
		} catch (RuntimeException re) {
			logger.error("deleteYfExmaines failed");
			throw re;
		} finally {
			if (session != null) {
				releaseSession(session);
			}
		}
	}

	public List searchYfExmaine(YfExmaineForm yfExmaineForm, PageBean pageBean) {
		List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT * FROM yf_exmaine WHERE 1=1 ");
		sql = getStringBuffer(yfExmaineForm, sql, args);
		sql.append(" order by examine_date desc ");
		return getPageInfo(pageBean, sql.toString(), args);
	}

	/**
	 * 查询条件的封装
	 * 
	 * @param departmentForm
	 * @return
	 */
	private StringBuffer getStringBuffer(YfExmaineForm yfExmaineForm,
			StringBuffer buf, List args) {
		/*
		 * 需要加入查询条件时封装
		 */

		if (StringUtils.isNotBlank(yfExmaineForm.getExamineFlag())) {
			buf.append(" and EXAMINE_FLAG like ? ");
			args.add("%" + yfExmaineForm.getExamineFlag().trim() + "%");
		}
		if (StringUtils.isNotBlank(yfExmaineForm.getProcessId())) {
			buf.append(" and process_id = ? ");
			args.add(yfExmaineForm.getProcessId().trim());
		}
		return buf;
	}

}
